import java.util.Scanner;
//神奇数
public class Test3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int count = 0;
        for (int i = Math.max(a,10) ; i < b ; i++) {
            count += check(i);
        }
        System.out.println(count);
    }
    public static Boolean isPrim(int x) {
        if(x < 2) {
            return false;
        }
        for (int i = 2; i < Math.sqrt(x) ; i++) {
            if(x % i == 0) {
                return false;
            }
        }
        return true;
    }
    public static int check(int x) {
        int[] arr = new int[10];
        int n = 0;
        while(x != 0) {
           arr[n++] =  x % 10;
           x = x / 10;
        }
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length; j++) {
                if(arr[i] != 0 && i != j) {
                  if(isPrim(arr[i] * 10 + arr[j])) {
                      return 1;
                  }
                }
            }
        }
        return 0;
    }
}
